﻿using Newtonsoft.Json;
using SerialPort_Assistant.Config;
using SerialPort_Assistant.ViewModel;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Ports;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace SerialPort_Assistant
{
    /// <summary>
    /// MainView.xaml 的交互逻辑
    /// </summary>
    public partial class MainView : Window
    {
        private MainViewModel viewModel;
        public MainView()
        {
            InitializeComponent();
 
            viewModel = new MainViewModel();
            AppConfigManager.RestoreAppStatus(viewModel);
            this.DataContext = viewModel;
        }

        #region 初始化窗口状态
        private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.DragMove();
        }

        private void MinSizeClick(object sender, RoutedEventArgs e)
        {
            WindowState = WindowState.Minimized;
        }

        private void MaxSizeClick(object sender, RoutedEventArgs e)
        {
            WindowState = WindowState == WindowState.Normal ? WindowState.Maximized : WindowState.Normal;
        }

        private void ExitAppClick(object sender, RoutedEventArgs e)
        {
            AppConfigManager.PersistenceAppStatus();
            Application.Current.Shutdown();
        }
        #endregion

        private void NewKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key != Key.Enter)
                return;
            MessageBox.Show("用户输入了回车键");
        }
    }
}
